package com.uphone.kingmall.adapter;

import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.china.zhuoyue.R;
import com.uphone.kingmall.bean.CircleIndexShopBean;
import com.uphone.kingmall.utils.CommonUtil;

import java.util.List;

/**
 * <pre>
 *     author : radish
 *     e-mail : 15703379121@163.com
 *     time   : 2019/3/19
 *     desc   :
 * </pre>
 */
public class CricleIndexShopAdapter extends BaseQuickAdapter<CircleIndexShopBean.DataBean, BaseViewHolder> {
    private CircleIndexShopClickListener listener;

    public CricleIndexShopAdapter() {
        super(R.layout.kingmall_item_rv_cricle_index_shop);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final CircleIndexShopBean.DataBean item) {
        int circleType = item.getCircleType() - 1;
//        if (circleType >= 0 && circleType < ConstansUtils.Cricle_Type.length) {
        helper.setText(R.id.tv_item, item.getCircleName());
//        }
        helper.getView(R.id.tv_more).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.moreClick(v, helper.getLayoutPosition(), item);
                }
            }
        });
        RecyclerView recyclerview = helper.getView(R.id.recyclerview);
        recyclerview.setLayoutManager(new LinearLayoutManager(mContext));
        CircleAdpater circleAdpater = new CircleAdpater();
        recyclerview.setAdapter(circleAdpater);
        final List<CircleIndexShopBean.DataBean.ShopsBean> shops = item.getShops();
        if (shops != null) {
            circleAdpater.setNewData(CommonUtil.getList(shops, 4));
        }
        circleAdpater.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (listener != null) {
                    listener.itemChildClick(view, helper.getLayoutPosition(), position, item, shops.get(position));
                }
            }
        });


    }

    public void setItemClickListener(CircleIndexShopClickListener listener) {
        this.listener = listener;
    }

    public interface CircleIndexShopClickListener {
        void moreClick(View v, int position, CircleIndexShopBean.DataBean item);

        void itemChildClick(View v, int position, int childPosition, CircleIndexShopBean.DataBean item, CircleIndexShopBean.DataBean.ShopsBean childItem);
    }
}
